<?php
namespace app\shop\controller\admin;

use app\admin\library\AdminController;


class Setting extends AdminController{
    

     public function __construct()
     {
        parent::__construct();
        $this->power('shop.setting.base');
     }
    public function onIndex(){
       
        $this->pageTitle = '设置';
        $this->pageIcon  = 'fa-cog';

        $this->set('api',$this->app->config('api')->toArray());
        $this->set('member',$this->app->config('member')->toArray());
        $this->set('freight',$this->app->config('freight')->toArray());

        return $this->display();
    }

    public function onSaveApi(){
        $data['listCacheTime'] = $this->post('listCacheTime',$this->check()->type('int')->default(10*60));
        $data['randomListDeep'] = $this->post('randomListDeep',$this->check()->type('int')->default(100));
        $data['tagListDeep'] = $this->post('tagListDeep',$this->check()->type('int')->default(100));

        $config = $this->app->config('api');
        $config->setData($data);
        $config->save();
        return true;
    }

    public function onSaveMember(){
        $data['tagUpdateTime'] = $this->post('tagUpdateTime',$this->check()->type('int')->default(10*60));
        $data['tagLength'] = $this->post('tagLength',$this->check()->type('int')->default(4));
        $data['tagSeachDeep'] = $this->post('tagSeachDeep',$this->check()->type('int')->default(100));
        $data['tagSeachType'] = $this->post('tagSeachType',$this->check()->default('time,num'));
        $config = $this->app->config('member');
        $config->setData($data);
        $config->save();
        return true;
    }

    public function onSaveFreight(){
        $data['money'] = $this->post('money',$this->check()->type('int')->default(0));
        $data['free'] = $this->post('free',$this->check()->type('int')->default(0));
        $data['desc'] = $this->post('desc',$this->check()->default(''));
        $config = $this->app->config('freight');
        $config->setData($data);
        $config->save();
        return true;
    }
}